﻿using System;
using Windows.ApplicationModel.Activation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace App16
{
    public sealed partial class App : Application
    {
        public App()
        {
            this.InitializeComponent();
        }

        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            CreateRootFrame(typeof(MainPage));
            Window.Current.Activate();
        }

        private Frame CreateRootFrame(Type type, object args = null)
        {
            var rootFrame = Window.Current.Content as Frame;
            if (rootFrame == null)
                Window.Current.Content = rootFrame = new Frame();
            if (rootFrame.Content == null)
                rootFrame.Navigate(type, args);
            return rootFrame;
        }

        #region Active Directory Application Library

        public static string ServiceResource = "https://univ1234.onmicrosoft.com/UnivService";

#if WINDOWS_PHONE_APP

        internal static AdalService Adal = new AdalService("univ1234.onmicrosoft.com", "22239c1e-16d6-4c10-aa3f-79f7432554bd");

        protected override void OnActivated(IActivatedEventArgs e)
        {
            CreateRootFrame(typeof(MainPage));
            if (e.Kind == ActivationKind.WebAuthenticationBrokerContinuation)
                Adal.Continuation(e as IActivatedEventArgs as IWebAuthenticationBrokerContinuationEventArgs);
            Window.Current.Activate();
        }

#elif WINDOWS_APP

        internal static AdalService Adal = new AdalService("univ1234.onmicrosoft.com", "2056b825-a073-4e3c-8f80-409500a04ccf");

        protected override void OnActivated(IActivatedEventArgs e)
        {
            CreateRootFrame(typeof(MainPage));
            Window.Current.Activate();
        }

#endif

        #endregion
    }
}